<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>购物车</title>
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css">
    <link href="css/mystyle.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

    <script>
        function deleteShoppingCartProduct(orderId) {
            //用户安全提示
            if (confirm("您确定要删除吗？")) {
                //访问路径
                location.href = "${pageContext.request.contextPath}/shoppingCartServlet?demand=delChoose&orderId=" + orderId;
            }
        }

        function emptyShoppingCart() {
            //用户安全提示
            if (confirm("您确定要清空购物车吗？")) {
                //访问路径
                location.href = "${pageContext.request.contextPath}/shoppingCartServlet?demand=empty";
            }
        }
    </script>

    <style>
        .shoppingCartText {
            width: 40px;
            height: 32px;
            display: inline-block;
            margin-left: 5px;
            margin-right: 5px;
            text-align: center;
        }
    </style>
</head>

<body>
<!-- 顶部banner -->
<div class="container">
    <div class="banner">
        <ul class="nav nav-pills topmenu">
            <li role="presentation"><a href="${pageContext.request.contextPath}/productServlet">主页</a></li>
            <li role="presentation"><a href="CommodityRegistered.jsp">用户注册</a></li>
            <li role="presentation"><a href="CommodityForgetPassword.jsp">忘记密码</a></li>
            <li role="presentation"><a href="${pageContext.request.contextPath}/feedbackServlet?demand=showAll">意见反馈</a>
            </li>
        </ul>
    </div>
</div>

<!--购物车-->
<div class="container showMove" style="margin-top: 20px;">
    <div class="row">
        <div class="col-md-3">
            <div class="panel panel-info">
                <div class="panel-heading">用户信息</div>
                <div class="panel-body text-center">
                    <table class="table table-bordered table-striped">
                        <tbody>
                        <tr>
                            <td rowspan="4"><img src="images/face/${sessionScope.loginCustomer.header}" width="100%"
                                                 alt=""/></td>
                            <td><a href="${pageContext.request.contextPath}/shoppingCartServlet?demand=show">我的购物车</a>
                            </td>
                        </tr>
                        <tr>
                            <td><a href="${pageContext.request.contextPath}/ordersServlet?demand=show&user=${sessionScope.loginCustomer.name}">我的订单</a></td>
                        </tr>
                        <tr>
                            <td><a href="${pageContext.request.contextPath}/feedbackServlet?demand=showAll">意见反馈</a></td>
                        </tr>
                        <tr>
                            <td><a href="CommodityCustomerMaterial.jsp">修改我的资料</a></td>
                        </tr>
                        <tr>
                            <td>${sessionScope.loginCustomer.name}</td>
                            <td><a href="${pageContext.request.contextPath}/productServlet">退出</a></td>
                        </tr>
                        <tr>
                            <td colspan="2">${requestScope.CookieShowTime_msg}</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-9">
            <div class="container-fluid text-center">
                <table class="table table-bordered table-striped">
                    <tbody>
                    <tr>
                        <td colspan="7" align="left" class="bg-info"><img src="images/logo/cart.JPG">我的购物车</td>
                    </tr>

                    <tr>
                        <td>编号</td>
                        <td>商品编号</td>
                        <td>商品名称</td>
                        <td>单价</td>
                        <td>数量</td>
                        <td>金额</td>
                        <td>操作</td>
                    </tr>

                    <c:forEach items="${sessionScope.orderAllDetails}" var="orderProduct" varStatus="number">
                        <tr>
                            <td>${number.count}</td>
                            <td>${orderProduct.id}</td>
                            <td>${orderProduct.name}</td>
                            <td>${orderProduct.price}</td>
                            <td>
                                <div class="input-group">
                                    <a href="${pageContext.request.contextPath}/shoppingCartServlet?demand=less&id=${orderProduct.id}" type="button" class="btn btn-default" >-</a>
                                    <div class="shoppingCartText"><strong>${orderProduct.number}</strong></div>
                                    <a href="${pageContext.request.contextPath}/shoppingCartServlet?demand=plus&id=${orderProduct.id}" type="button" class="btn btn-default">+</a>
                                </div>
                            </td>
                            <td>￥${orderProduct.price * orderProduct.number}</td>
                            <td>
                                <a href="javascript:deleteShoppingCartProduct('${orderProduct.order_id}');"
                                   type="submit" class="btn btn-default">删除</a>
                                    <%--                                <button href="${pageContext.request.contextPath}/shoppingCartServlet?demand=delChoose&orderId=${orderProduct.order_id}" class="btn btn-default" type="button">删除</button>--%>
                            </td>
                        </tr>
                        <%--@elvariable id="totalAmount" type=""--%>
                        <c:set var="totalAmount" value="${orderProduct.price * orderProduct.number + totalAmount}"/>
                    </c:forEach>

                    <tr>
                        <td colspan="7" align="right">总计：${totalAmount}元</td>
                    </tr>

                    <tr>
                        <td colspan="7">
                            <a href="${pageContext.request.contextPath}/CommodityHomeLogin.jsp" class="btn btn-info"
                               style="margin-left: 200px">继续购物</a>
                            <a href="${pageContext.request.contextPath}/paymentServlet?demand=pay" class="btn btn-info"
                               style="margin-left: 70px">结账</a>
                            <a href="javascript:emptyShoppingCart();" class="btn btn-info"
                               style="margin-left: 70px">清空</a>
                            <%--                            <button href="${pageContext.request.contextPath}/CommodityHomeLogin.jsp" class="btn btn-info"  style="margin-left: 200px">继续购物</button>--%>
                            <%--                            <button class="btn btn-info" type="button" style="margin-left: 70px">结账</button>--%>
                            <%--                            <button class="btn btn-info" type="button" style="margin-left: 70px">清空</button>--%>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<div class="footerbg center showMove">
    <p> Designed and built with all the love in the world by @mdo and @fat. Maintained by the core team with the help of
        our contributors.</p>
</div>

</body>
</html>

